package ro.gateway.aida.obj;

import java.util.Hashtable;


/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 *
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: AIDASector.java,v 1.1 2004/10/24 23:37:10 mihaipostelnicu Exp $
 */
public class AIDASector extends LocalizedItem {
	protected String dac5_code;
	protected String crs_code;
	protected LangString title;
	protected AIDASector parent;
	protected int parent_ro_aida_code = -1;
	protected int ro_aida_code = -1;

	public AIDASector() {
		title = new LangString();
	}

	public int getRo_aida_code() {
		return ro_aida_code;
	}

	public void setRo_aida_code(int ro_aida_code) {
		this.ro_aida_code = ro_aida_code;
	}

	public void setDac5_code(String dac5_code) {
		this.dac5_code = dac5_code;
	}

	public String getDac5_code() {
		return dac5_code;
	}

	public void setCrs_code(String crs_code) {
		this.crs_code = crs_code;
	}

	public String getCrs_code() {
		return crs_code;
	}

	public void setParent_ro_aida_code(int parent_ro_aida_code) {
		this.parent_ro_aida_code = parent_ro_aida_code;
	}

	public int getParent_ro_aida_code() {
		return parent_ro_aida_code;
	}

	/**
	 * @param lang
	 * @return
	 */
	public String getTitle(String lang) {
		if (lang == null)
			return null;

		lang = lang.toLowerCase(); //lang e zapacit alte clase, pana acu lucram cu limba cu litere mici...

		return title.getString(lang);
	}

	/**
	 * @param lang
	 * @param title
	 */
	public void setTitle(String lang, String title) {
		if ((title == null) || (lang == null)) {
			System.err.println("incercare nereusita de setare titlu pt. sector");

			return;
		}

		this.title.setString(lang, title);
	}

	public void setParent(AIDASector parent) {
		this.parent = parent;

		if (parent != null)
			this.parent_ro_aida_code = parent.getRo_aida_code();
	}

	public AIDASector getParent() {
		return parent;
	}

	/**
	 * @return
	 */
	public LangString getTitle() {
		return title;
	}

	public String getTitleAsString() {
		return title.getString(viewLang);
	}

	/**
	 * @param string
	 */
	public void setTitle(LangString string) {
		title = string;
	}

	/**
	 * @return nivelul sectorului this (0==parent null, 1 parent nenul && bunic null, etc)
	 */
	public int getLevel() {
		return _getLevel(0);
	}

	protected int _getLevel(int depth) {
		if (parent == null) return 0;
		if (depth > 10) {
			System.err.println("sectors depth:" + 10 + ", and that's doesn't sound good...");
			return 0;
		}
		return 1 + parent._getLevel(depth + 1);
	}

	public static final String LIST = "Sector_LIST";
}
